<?php
$isReloadable = false;
require_once("../../pers/inc.config.php");
require_once(RGL_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(RGL_FS_WEB_ROOT.'/app/_inc/funct.html.php');
require_once(RGL_FS_WEB_ROOT.'/app/gest/util/_inc/funct.confDb.php');

if (reqVar('azione') == 'cambia') {
	$msgPag = cambia();
}

$sCmdL  = "";

$sCmdR  = "&nbsp;&nbsp;&nbsp";
$sCmdR .=  "<a class='cmd1' href='javascript:document.frm1.submit();'>cambia</a>\n";
$sCmdR .=  cmdTorna();
testaHtml('Opzioni personali', $msgPag, 'opzp');
?>
<form name='frm1' action='<?=$_SERVER['PHP_SELF']?>' method='post' enctype="multipart/form-data">
<input type='hidden' name='azione' value="cambia">
<input type='hidden' name='xsn' value="<?=XSN?>">
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="30%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
	<tr>
		<td class="tit1" colspan='2' align='center'>Cambio password</td>
	</tr>
	<tr>
		<td class="lab1" width='50%'>
			Nuova password
		</td>
		<td class="txt1" width='50%'>
			<?php echo getHtmlPassword('new_pwd',20)?>
		</td>
	</tr>
	<tr>
		<td class="lab1">
			Ridigita password
		</td>
		<td class="txt1">
			<?php echo getHtmlPassword('rid_pwd',20)?>
		</td>
	</tr>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
</form>
<?
codaHtml();
exit();

function cambia() {
	global $objDB,$objSess;
	$msg = '';
	if (reqVar('new_pwd') != reqVar('rid_pwd')) {
		return 'password ridigitata diversa';
	}
	
	$sSql = "UPDATE rgl_utenti SET password = 'X".reqVarAS('new_pwd')
		."' WHERE id_utente = ".intval($objSess->idUtente);
	$objDB->query($sSql,'selUten');
	return "password cambiata";
}
